﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using FortuneHeavenCommon.Enum;
using Jzy.Core.Common.Basic;
using FortuneHeavenCommon.ComMethod;

namespace FortuneHeaven.Web.Common
{
    public class BasePage : Page
    {
        public void SetPageHeader(MainPageTabType type)
        {
            (this.Master.FindControl("ucheader") as FortuneHeaven.Web.Controls.Header).SelectTab = type;
        }

        public string GetTitle(object obj)
        {
            if (obj == null || !(obj is string))
            {
                return "";
            }
            string input = (string)obj;
            if (!string.IsNullOrEmpty(input) && input.Length > 12)
            {
                return string.Format("{0}{1}", input.Substring(0, 10), "...");
            }
            return input;
        }

        protected void ShowCurError(string message)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "error", string.Format("alert('{0}');", message), true);
        }

        protected void ShowCurMessage(string message)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "message", string.Format("alert('{0}');", message), true);
        }

        public void TransferErrorPage()
        {
            Response.Redirect(string.Format("{0}{1}", GlobalVar.WebAppPath, "Error.htm"));
        }

        public string GetPagesURL(string path, object str)
        {
            return FortuneHeaven.Web.Common.BasePath.AdminURL + path + (str == null ? "" : str.ToString());
        }
        //public string GetPagesURL(CommonPath path, string str)
        //{
        //    return FortuneHeaven.Web.Common.BasePath.AdminURL + path + str;
        //}
        public int GetInt(string input)
        {
            int k = 0;
            int.TryParse(input, out k);
            return k;
        }
    }
}